package com.cmict.data.common.mail.config;

import com.cmict.data.common.mail.sender.MailSender;
import com.cmict.data.common.mail.sender.MailSenderImpl;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.autoconfigure.mail.MailProperties;
import org.springframework.boot.autoconfigure.mail.MailSenderAutoConfiguration;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.mail.javamail.JavaMailSender;

@AutoConfigureAfter(MailSenderAutoConfiguration.class)
@Configuration
public class MailAutoConfiguration {

    @Bean
    @ConditionalOnMissingBean(MailSender.class)
    @ConditionalOnProperty(prefix = "spring.mail", name = "host")
    public MailSender mailSenderImpl(JavaMailSender javaMailSender,
                                     ApplicationEventPublisher applicationEventPublisher) {
        System.out.println("初始化了----------");
        return new MailSenderImpl(javaMailSender, applicationEventPublisher);
    }

}